
from clickFuUtils import cfAction
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from settingZoom import Ui_ZoomSetting

zoomItem="/clickfu/flickr/zoom"
zoomDefault=5


class flickrPics(cfAction):
    def __init__(self,iface):
        cfAction.__init__(self,self.name(),iface)
        return None
    def tag(self):
        return "flickrPics"
    def name(self):
        return "Flickr Maps"
    def desc(self):
        return "Show Flickr photos near point"

    def createURL(self,lat,long):
        url = "http://www.flickr.com/map/?fLat=%s&fLon=%s&zl=%s" % (lat,long,getZoom())
        return url

def getZoom():
    return QSettings().value(zoomItem,QVariant(zoomDefault)).toInt()[0]
def setZoom(n):
    QSettings().setValue(zoomItem,n)

class flickrSettings(QAction):

    def __init__(self,iface):
        QAction.__init__(self,self.name(),iface.mainWindow())
        QObject.connect(self,SIGNAL("triggered()"),self.setMe)
        return None

    def name(self):
        return "Flickr"

    def setMe(self):
        window=QDialog()
        ui=Ui_ZoomSetting()
        ui.setupUi(window)
        ui.zoomSlider.setInvertedAppearance(True)
        ui.zoomSlider.setRange(1,17)
        ui.valueBox.setRange(1,17)
        ui.zoomSlider.setValue(getZoom())
        if window.exec_():
            setZoom(ui.zoomSlider.value())

